Imports System.IO

Public Class Log

	' Chagen how the logging works so that individual messages can be tracked. 
	Public Shared Sub LogData(ByVal data As String, ByVal refid As String)
		Dim nightfile As String

		If Now.Hour > 8 Then
			nightfile = "wk"
		Else
			nightfile = "am"
		End If

		data = data.Replace("<?xml version=""1.0"" encoding=""utf-8""?>", "")

		'Dim outfile As String = "logfile_" & Now.Year & Now.Month.ToString("00") & Now.Day.ToString("00") & nightfile & ".txt"
		Dim outfile As String = "\lf_" & DateTime.Now.ToString("yyyyMMddHHmmss") & "_" & refid & ".xml"
		Dim path As String = Application.ExecutablePath
		path = path.ToLower().Replace("tcsclearing.exe", "")
		Dim filepath As String = path & "logs\" & DateTime.Now.ToString("yyyyMMdd")

		If Directory.Exists(filepath) = False Then
			Directory.CreateDirectory(filepath)
		End If
		Dim fout As New FileStream(filepath & outfile, FileMode.OpenOrCreate, FileAccess.Write)
		Dim sr As New StreamWriter(fout)

		'sr.Write("<Message>" & vbCrLf & Date.Now.ToString & " " & data & vbCrLf & "</Message>" & vbCrLf)
		sr.Write(data & vbCrLf)
		sr.Close()

		fout.Close()
		' Console.WriteLine(Date.Now.ToString & " " & data)
	End Sub

	Public Shared Sub LogData(ByVal data As String)
		Dim nightfile As String

		If Now.Hour > 8 Then
			nightfile = "wk"
		Else
			nightfile = "am"
		End If

		Dim outfile As String = "logfile_" & Now.Year & Now.Month.ToString("00") & Now.Day.ToString("00") & nightfile & ".txt"
		Dim path As String = Application.ExecutablePath
		path = path.ToLower().Replace("tcsclearing.exe", "")

		Dim fout As New FileStream(path & "logs\" & outfile, FileMode.Append, FileAccess.Write)
		Dim sr As New StreamWriter(fout)

		sr.Write("<Message>" & vbCrLf & Date.Now.ToString & " " & data & vbCrLf & "</Message>" & vbCrLf)
		sr.Close()

		' Console.WriteLine(Date.Now.ToString & " " & data)


	End Sub

End Class

